package org.example.struct.array2;

import java.util.Arrays;

/**
 * @author liyishan
 * @date 2024/8/9 10:27
 * @apiNote
 */

public class Test03132MinimumAddedInteger {
    public int minimumAddedInteger(int[] nums1, int[] nums2) {
        int m = nums1.length;
        int n = nums2.length;
        Arrays.sort(nums1);
        Arrays.sort(nums2);
        for(int i : new int[]{2,1,0}){
            int left = i+1,right = 1;
            while(left<m&& right < n){
                if(nums1[left] - nums2[right] == nums1[i] - nums2[0]){
                    right++;
                }
                left++;
            }
            if (right == n){
                return nums2[0] - nums1[i];
            }
        }
        return 0;
    }
}
